from flask import Blueprint, jsonify
from src.core.trade_processor import TradeProcessor
from src.storage.storage_interface import StorageInterface
from src.adapters.platform_interface import PlatformAdapter

bp = Blueprint('statistics', __name__)

@bp.route('/statistics/data')
def get_statistics_data():
    """获取统计数据"""
    print("hello ----- statistics.py")
    try:
        # 初始化存储和平台适配器
        storage = StorageInterface()
        platform = PlatformAdapter()
        
        # 初始化交易处理器
        processor = TradeProcessor(platform, storage)
        
        # 获取所有交易记录
        trades_df = storage.get_all_trades()
        
        # 计算统计数据
        stats = processor.calculate_statistics(trades_df)
        
        return jsonify(stats)
    except Exception as e:
        return jsonify({'error': str(e)}), 500 


# src/routes/statistics.py

from flask import render_template

@bp.route('/statistics/ew')
def statistics_ew_new():
    return render_template('statistics/ew.html')